<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AMQP 协议深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            margin-top: -8px;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        
        .icon-box {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        
        .step-number {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 18px;
            flex-shrink: 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fade-in">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">AMQP 协议深度解析</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                探索高级消息队列协议的核心机制，理解分布式系统中可靠消息传递的艺术
            </p>
            <div class="mt-8 flex justify-center space-x-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-layer-group mr-2"></i>开放标准
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-shield-alt mr-2"></i>可靠传输
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-expand-arrows-alt mr-2"></i>高度可扩展
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 animate-fade-in">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">A</span>MQP（Advanced Message Queuing Protocol）是一个开放标准的消息中间件协议，用于在分布式系统中交换消息。AMQP 的设计目标是提供一种可靠、可扩展、并且能够保证消息传递的协议。它主要用于消息的发布、路由、队列和消费。
            </p>
        </div>

        <!-- Protocol Model Section -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">协议模型</h2>
            <p class="text-lg text-gray-700 mb-8">AMQP 协议的核心模型包括几个关键的组件：</p>
            
            <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="icon-box">
                        <i class="fas fa-paper-plane"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">生产者（Producer）</h3>
                    <p class="text-gray-600">发送消息到消息队列系统的应用程序。</p>
                </div>
                
                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="icon-box">
                        <i class="fas fa-inbox"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">消费者（Consumer）</h3>
                    <p class="text-gray-600">从消息队列系统中接收并处理消息的应用程序。</p>
                </div>
                
                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="icon-box">
                        <i class="fas fa-exchange-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">交换机（Exchange）</h3>
                    <p class="text-gray-600">接收生产者发送的消息，并根据预定义的规则将消息路由到一个或多个队列。</p>
                </div>
                
                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="icon-box">
                        <i class="fas fa-list"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">队列（Queue）</h3>
                    <p class="text-gray-600">存储消息的缓冲区，消费者从队列中获取消息进行处理。</p>
                </div>
                
                <div class="bg-white rounded-xl p-6 card-hover">
                    <div class="icon-box">
                        <i class="fas fa-link"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">绑定（Binding）</h3>
                    <p class="text-gray-600">交换机与队列之间的关系，定义了消息的路由规则。</p>
                </div>
            </div>
        </div>

        <!-- Message Flow Visualization -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">消息流转可视化</h2>
            <div class="mermaid">
                graph LR
                    P[生产者] -->|发送消息| E[交换机]
                    E -->|路由规则| Q1[队列1]
                    E -->|路由规则| Q2[队列2]
                    E -->|路由规则| Q3[队列3]
                    Q1 --> C1[消费者1]
                    Q2 --> C2[消费者2]
                    Q3 --> C3[消费者3]
                    
                    style P fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style Q1 fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style Q2 fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style Q3 fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style C1 fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
                    style C2 fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
                    style C3 fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Message Delivery Process -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">消息传递过程</h2>
            <p class="text-lg text-gray-700 mb-8">AMQP 的消息传递过程涉及以下步骤：</p>
            
            <div class="space-y-6">
                <div class="bg-white rounded-xl p-6 flex items-start space-x-4 card-hover">
                    <div class="step-number">1</div>
                    <div class="flex-1">
                        <h3 class="text-xl font-bold mb-2">连接建立</h3>
                        <p class="text-gray-600">生产者和消费者通过 TCP/IP 连接到 AMQP 服务器（Broker）。连接建立后，客户端和服务器之间会交换一些初始化消息以协商协议版本和其他连接参数。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl p-6 flex items-start space-x-4 card-hover">
                    <div class="step-number">2</div>
                    <div class="flex-1">
                        <h3 class="text-xl font-bold mb-2">频道（Channel）创建</h3>
                        <p class="text-gray-600">在 AMQP 连接中，可以创建多个频道。频道是消息传递的逻辑通道，通过它们进行消息的发布和消费。频道用于在单一连接上处理多个消息流，减少了网络开销。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl p-6 flex items-start space-x-4 card-hover">
                    <div class="step-number">3</div>
                    <div class="flex-1">
                        <h3 class="text-xl font-bold mb-2">消息发布</h3>
                        <p class="text-gray-600">生产者将消息发送到交换机。消息可以包含一些元数据（如消息属性、路由键等）和负载数据（消息体）。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl p-6 flex items-start space-x-4 card-hover">
                    <div class="step-number">4</div>
                    <div class="flex-1">
                        <h3 class="text-xl font-bold mb-2">消息路由</h3>
                        <p class="text-gray-600 mb-4">交换机根据预定义的路由规则（绑定）将消息转发到一个或多个队列。交换机可以根据不同的类型来决定消息的路由方式：</p>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold text-purple-700 mb-1"><i class="fas fa-arrow-right mr-2"></i>直接交换机</h4>
                                <p class="text-sm text-gray-600">根据消息的路由键直接将消息路由到队列。</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold text-purple-700 mb-1"><i class="fas fa-hashtag mr-2"></i>主题交换机</h4>
                                <p class="text-sm text-gray-600">根据消息的路由键模式匹配多个队列。</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold text-purple-700 mb-1"><i class="fas fa-code-branch mr-2"></i>分裂交换机</h4>
                                <p class="text-sm text-gray-600">将消息广播到所